﻿<%@ Page Title="Permission setting" Language="C#" MasterPageFile="~/Main.Master"
    AutoEventWireup="true" CodeBehind="PrivilegeSetting.aspx.cs" Inherits="NetDon.OA.Portal.Admin.PrivilegeSetting" %>

<%@ Register Assembly="NineRays.WebControls.FlyTreeView" Namespace="NineRays.WebControls"
    TagPrefix="NineRays" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script language="javascript" type="text/javascript">
        var checkingNode = null;
        function nodeChecked(sender, node, eventType) {
            if ((eventType == "checked" || eventType == "unchecked") && node != checkingNode) {
                checkChildren(node);
                if (node.getAttribute('Type') != 'Operation') {
                    checkParent(node.getParent());
                }
            }
        }
        function checkChildren(node) {
            for (var i = 0, I = node.getChildNodes().length; i < I; i++) {
                checkingNode = node.getChildNodes()[i];
                node.getChildNodes()[i].setChecked(node.getChecked());
                checkingNode = null;
                checkChildren(node.getChildNodes()[i]);
            }
        }
        function checkParent(node) {
            if (node == null) return;
            var exist = existCheckChild(node);
            if (node.getChecked() != exist) {
                checkingNode = node;
                node.setChecked(exist);
                checkingNode = null;
                checkParent(node.getParent());
            }
        }
        function existCheckChild(node) {
            for (var i = 0, col = node.getChildNodes(); i < col.length; i++) {
                if (col[i].getChecked()) return true;
            }
            return false;
        }

        function treeRolesSelectedNodeChanged() {
            $get('<%=btnRefreshPermission.ClientID %>').click();
        }
        var roleId = null;
        var roleName = null;
        function treeNodeContextMenu(/*CFlyTreeView*/sender, /*CFlyTreeNode*/node, /*event*/event) {
            roleId = node.getValue();
            roleName = node.getText();
        }

        function menuDeleteRole() {
            $confirm('确认要删除此角色吗?', function (result) {
                if (result) {
                    $text($get('<%=fieldValue.ClientID %>'), roleId);
                    $get('<%=btnDeleteRole.ClientID %>').click();
                }
            });
        }

        function menuModifyRole() {
            $prompt('请输入角色名称', roleName, function (sender, value) {
                PageMethods.ModifyRole(roleId, value, saveRoleCallback, null, { prompter: sender, value: value });
            });
        }


        function btnAddRoleClick() {
            $prompt('请输入角色名称', '', function (sender, value) {
                PageMethods.AddRole(value, saveRoleCallback, null, { prompter: sender, value: value });
            });
        }
        function saveRoleCallback(result, context) {
            if (result) {
                context.prompter.hide();
                $get('<%=btnRefreshRoles.ClientID %>').click();
            } else {
                $alert(String.format("角色名称 '{0}' 已存在.", context.value));
            }
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <ContentTemplate>
            <table border="0" cellpadding="0" cellspacing="0" style="width: 100%">
                <tr>
                    <td valign="top" style="width: 300px">
                        <NineRays:FlyTreeView ID="treeRoles" runat="server" Width="300px" DrawLines="false"
                            OnSelectedNodeChangedJavascript="treeRolesSelectedNodeChanged" ContextMenuID="menuRoles"
                            OnContextMenuJavascript="treeNodeContextMenu">
                        </NineRays:FlyTreeView>
                        <NineRays:FlyContextMenu ID="menuRoles" runat="server">
                            <Items>
                                <NineRays:FlyMenuItem Text="修改" AutoPostBack="false" Javascript="menuModifyRole" />
                                <NineRays:FlyMenuItem Text="删除" AutoPostBack="false" Javascript="menuDeleteRole" />
                            </Items>
                        </NineRays:FlyContextMenu>
                        <div style="margin-left: 10px">
                            <asp:Button ID="btnCreateRole" runat="server" SkinID="Button80" Text="创建" OnClientClick="btnAddRoleClick();return false;" />
                            <%--<asp:Button ID="btnSave" runat="server" Text="保存" OnClick="btnSave_Click" />--%>
                        </div>
                    </td>
                    <td valign="top">
                        <div style="float: left; margin-left: 10px;">
                            <asp:TabContainer Style="margin-top: 10px;" ID="tabContainer" runat="server">
                                <asp:TabPanel runat="server" ID="tabPanel1">
                                    <HeaderTemplate>
                                        <asp:Literal ID="Literal1" runat="server" Text="菜单"></asp:Literal>
                                    </HeaderTemplate>
                                    <ContentTemplate>
                                        <NineRays:FlyTreeView ID="tvFunctions" runat="server" OnNodeEventJavascript="nodeChecked">
                                        </NineRays:FlyTreeView>
                                    </ContentTemplate>
                                </asp:TabPanel>
                            </asp:TabContainer>
                        </div>
                    </td>
                </tr>
            </table>
            <asp:HiddenField ID="fieldValue" runat="server" />
            <asp:Button ID="btnDeleteRole" runat="server" OnClick="btnDeleteRole_Click" Style="display: none"
                CausesValidation="false" />
            <asp:Button ID="btnRefreshRoles" runat="server" OnClick="btnRefreshRoles_Click" Style="display: none"
                CausesValidation="false" />
            <asp:Button ID="btnRefreshPermission" runat="server" OnClick="btnRefreshPermission_Click"
                Style="display: none" CausesValidation="false" />
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
